import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.mapreduce.Cluster;
import org.apache.hadoop.mapreduce.Counters;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.JobID;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

/**
 * Created by Administrator on 2016/9/22 0022.
 */
public class JobCounterTest extends Configured implements Tool {

    public static void main(String[] args) throws Exception {
        int exitCode = ToolRunner.run(new JobCounterTest(), args);
        System.exit(exitCode);
    }

    @Override
    public int run(String[] args) throws Exception {
        if (args.length != 1) {
            return -1;
        }

        Cluster cluster = new Cluster(getConf());

        Job job = cluster.getJob(JobID.forName(args[0]));
        Counters counters = job.getCounters();
        long miss = counters.findCounter(WordCountJava.Temperature.Missing).getValue();

        System.out.println("word-count-java's Temperature.Missing counter = " + miss);
        return 0;
    }
}
